<?php
/**
 *
 * @Author nikm $
 *
 * @Date 2012-3-9 $
 */

if(!defined('FROM_INDEX')) exit('Invalid request');

require ROOT_PATH.'servlet/module/master.mod.php';

class moduleObj extends masterObj
{
	function __construct($request)
	{
		parent::__construct($request);
		
		$this->excute();
	}
	
	private function excute()
	{
		switch($this->act)
		{
			case 'list':
				$this->getList();
				break;
			case 'add':
				$this->addComment();
				break;
			default:
				$this->message('g_04', STATUS_E);
				break;
		}
		
		$this->showResponse();
	}
	
	private function getList()
	{
		//DBFunction::getInstance()->setDebug();
		
		$result = search_comment_list($this->request);
		$list = $result['result'];
		
		if(!check_array($list)) $this->message('cm_01', STATUS_F);
		
		foreach($list as &$temp)
		{
			$temp['create_date'] = date('Y-m-d H:i:s', $temp['create_date']);
		}
		
		$this->response['status'] = STATUS_S;
		$this->response['count'] = (string)count($list);
		$this->response['list'] = $list;
	}
	
	private function addComment()
	{
		//DBFunction::getInstance()->setDebug();
		
		$this->request['bid'] = isset($this->request['bid']) ? (int)$this->request['bid'] : '';
		$this->request['uid'] = isset($this->request['uid']) ? (int)$this->request['uid'] : '';
		$this->request['service_score'] = isset($this->request['service_score']) ? (int)$this->request['service_score'] : 0;
		$this->request['env_score'] = isset($this->request['env_score']) ? (int)$this->request['env_score'] : 0;
		$this->request['price_score'] = isset($this->request['price_score']) ? (int)$this->request['price_score'] : 0;
		$this->request['desc'] = isset($this->request['desc']) ? $this->request['desc'] : '';
		
		$business = get_travel_item(array('id'=>$this->request['bid']));
		
		if(!check_array($business) || !isset($business['id']) || $business['id'] < 1)
		{
			$this->message('b_01', STATUS_E);
		}
		
		$result = add_comment($this->request);
		
		if($result)
		{
			$this->response['status'] = STATUS_S;
			$this->response['message_code'] = 'cm_02';
		}
		else
		{
			$this->response['status'] = STATUS_F;
			$this->response['message_code'] = 'cm_03';
		}
	}
}